package org.example.infrastructure.persistence.orm;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.example.domain.model.entity.url.UrlShortenerAccessLogs;
import org.example.domain.model.entity.url.req.UrlShortenerGroupStatsAccessRecordReq;
import org.example.domain.model.entity.url.req.UrlShortenerGroupStatsReq;
import org.example.domain.model.entity.url.req.UrlShortenerStatsReq;
import org.example.domain.model.entity.url.vo.UrlShortenerAccessLogsVo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Mapper
public interface UrlShortenerAccessLogsMapper extends BaseMapper<UrlShortenerAccessLogs> {
    void insertUrlShortenerAccessLogs(UrlShortenerAccessLogs urlShortenerAccessLogs);

    /**
     * 根据短链接获取指定日期内PV、UV、UIP数据
     */
    UrlShortenerAccessLogsVo findPvUvUidStatsByUrlShortener(@Param(value = "param") UrlShortenerStatsReq urlShortenerStatsReq);

    /**
     * 根据短链接获取指定日期内高频访问IP数据
     */
    List<HashMap<String, Object>> topIpByUrlShortenerList(@Param(value = "param") UrlShortenerStatsReq urlShortenerStatsReq);

    /**
     * 根据短链接获取指定日期内新旧访客数据
     */
    HashMap<String, Object> findUvTypeByUrlShortenerList(@Param(value = "param") UrlShortenerStatsReq urlShortenerStatsReq);

    List<UrlShortenerAccessLogs> selectAccessLogsGroupPage(@Param(value = "param") UrlShortenerGroupStatsAccessRecordReq req);

    List<Map<String, Object>> selectGroupUvTypeByUsers(@Param(value = "gid") String gid,
                                                       @Param(value = "startDate") String startDate,
                                                       @Param(value = "endDate") String endDate,
                                                       @Param(value = "userAccessLogsList") List<String> userAccessLogsList);

    List<UrlShortenerAccessLogs> selectStatsAccessRecordPage(@Param(value = "fullShortUrl") String fullShortUrl,
                                                             @Param(value = "startDate") String startDate,
                                                             @Param(value = "endDate") String endDate);

    List<Map<String, Object>> selectUvTypeByUsers(@Param(value = "gid") String gid, 
                                                  @Param(value = "fullShortUrl") String fullShortUrl, 
                                                  @Param(value = "enableStatus") Integer enableStatus, 
                                                  @Param(value = "startDate") String startDate, 
                                                  @Param(value = "endDate") String endDate, 
                                                  @Param(value = "userAccessLogsList") List<String> userAccessLogsList);

    /** 根据分组获取指定日期内PV、UV、UIP数据 */
    UrlShortenerAccessLogsVo findUrlShortenerAccessLogsVoByGroup(@Param(value = "param")UrlShortenerGroupStatsReq urlShortenerGroupStatsReq);

    /** 根据分组获取指定日期内高频访问IP数据 */
    List<HashMap<String, Object>> topIpByGroupList(@Param(value = "param") UrlShortenerGroupStatsReq urlShortenerGroupStatsReq);
}
